﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Profile;
using System.Data;
using System.Web.Security;

namespace WebSite.admin.member
{
    public partial class users_edit : BaseAdmin
    {
   

        // Methods
        private void Bind()
        {
            string sql = "select * from tbMemberank";
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                foreach (DataRow row in table.Rows)
                {
                    this.rankid.Items.Add(new ListItem(row["rank"].ToString(), row["rankid"].ToString()));
                }
            }
            for (int i = 100; i >= 0; i--)
            {
                int num = DateTime.Today.Year - i;
                this.birthdayYear.Items.Add(new ListItem(num.ToString(), num.ToString()));
            }
            for (int j = 1; j < 13; j++)
            {
                this.birthdayMonth.Items.Add(new ListItem(j.ToString(), j.ToString()));
            }
            for (int k = 1; k < 0x20; k++)
            {
                this.birthday3.Items.Add(new ListItem(k.ToString(), k.ToString()));
            }
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            SQLAccess.DoSql("update tbMember set sex='" + re.replace(this.sex.SelectedValue) + "',membername='" + re.replace(this.membername.Value) + "',birthday='" + re.replace(this.birthdayYear.SelectedValue) + "-" + re.replace(this.birthdayMonth.SelectedValue) + "-" + re.replace(this.birthday3.SelectedValue) + "',email='" + re.replace(this.email.Value) + "',xinprice='" + re.replace(this.xinprice.Value) + "',rankid=" + re.replace(this.rankid.SelectedValue) + " where memberid=" + base.Request.QueryString["mid"] + "");

            if (this.txtUserPassword.Text.Trim() != "")
            {
                SQLAccess.DoSql("update tbMember set memberpwd='" + FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtUserPassword.Text.Trim(), "MD5") + "' where memberid=" + base.Request.QueryString["mid"] + "");
            }
                base.Response.Write("<script language='javascript'>alert('修改成功！');window.location.href='member.aspx';</script>");
            base.Response.End();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!base.IsPostBack)
            {
                base.ValidateLoginRule(Gift.Model.ENUM.ERule.UserList);
                this.Bind();
                if (base.Request.QueryString["mid"] != null)
                {
                    this.upbind();
                }
            }
        }

        private void upbind()
        {
            string sql = "select * from tbMember where memberid=" + base.Request.QueryString["mid"] + " and isnull(flag,0)!=2 ";
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                this.memberlogin.Value = table.Rows[0]["memberlogin"].ToString();
                this.membername.Value = table.Rows[0]["membername"].ToString();
                this.email.Value = table.Rows[0]["email"].ToString();
                this.rankid.SelectedValue = table.Rows[0]["rankid"].ToString();
                this.sex.SelectedValue = table.Rows[0]["sex"].ToString();
                if (table.Rows[0]["birthday"].ToString() != "")
                {
                  //  string[] strArray = table.Rows[0]["birthday"].ToString().Split(new char[] { '-' });
                    DateTime dtBirth = DateTime.Parse(table.Rows[0]["birthday"].ToString());
                    this.birthdayYear.SelectedValue = dtBirth.Year.ToString();// strArray[0].ToString();
                    this.birthdayMonth.SelectedValue = dtBirth.Month.ToString();// strArray[1].ToString().Trim();
                    this.birthday3.SelectedValue = dtBirth.Day.ToString();// strArray[2].ToString().Trim();
                }
                this.xinprice.Value = table.Rows[0]["xinprice"].ToString();
                this.price1.Text = table.Rows[0]["price1"].ToString();
                this.price2.Text = table.Rows[0]["price2"].ToString();
                this.score1.Text = table.Rows[0]["score1"].ToString();
                this.score2.Text = table.Rows[0]["score2"].ToString();
                this.msn.Text = table.Rows[0]["msn"].ToString();
                this.qq.Text = table.Rows[0]["qq"].ToString();
                this.tel1.Text = table.Rows[0]["tel1"].ToString();
                this.tel2.Text = table.Rows[0]["tel2"].ToString();
                this.phone.Text = table.Rows[0]["phone"].ToString();
            }
        }


    }
}